package org.misalen.web.server.util;

import java.util.List;

import org.apache.log4j.Logger;
import org.misalen.utils.ListUtil;
import org.misalen.validate.ValidatorFactory;
import org.misalen.validate.exception.ValidateError;
import org.misalen.web.server.config.ErrorCode;
import org.misalen.web.server.exception.CustomerException;

public class FormUtil {
	private static final Logger logger = Logger.getLogger(FormUtil.class);

	/**
	 * 检查注解
	 * 
	 * @return 错误信息
	 * @throws CustomerException
	 */
	public static void validate(Object object) throws CustomerException {
		List<ValidateError> errors = ValidatorFactory.validate(object);
		if (!ListUtil.isNullOrEmpty(errors)) {
			for (ValidateError validateError : errors) {
				logger.error(object.getClass().getName() + "\t" + validateError.getMessage());
			}
			throw new CustomerException(ErrorCode.SYS_ERROR_CODE_502, errors.get(0).getMessage());
		}

	}
}
